<template>
  <van-form @submit="onSubmit" autocomplete="off">
    <van-field
      v-model="login.phone"
      name="phone"
      label="手机号码"
      placeholder="手机号码"
      :rules="[{ required: true, message: '请填写手机号码' }]"
    />
    <van-field
      v-model="login.password"
      type="password"
      name="password"
      label="登录密码"
      placeholder="登录密码"
      :rules="[{ required: true, message: '请填写登录密码' }]"
    />
    <div style="margin: 16px">
      <van-button round block type="info" native-type="submit">登录</van-button>
    </div>
  </van-form>
</template>


<script>
export default {
  name: "signin",
  data() {
    return {
      login: {
        phone: this.$route.query.phone,
      },
    };
  },
  mounted() {
    this.login = {
      ...this.login,
      phone: this.$route.query.phone
        ? this.$route.query.phone
        : localStorage.getItem("appphone"),
    };
  },
  methods: {
    onSubmit(value) {
      console.log("submit", value);
      this.$ajax
        .login(value)
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.userphone = value.phone;

            localStorage.setItem("appphone", value.phone);
            localStorage.setItem("server_token", res.token);
            this.changeAppPhone(value.phone);
            this.resetUserInfo();
            this.$nextTick(() => {
              this.$router.push({ name: "my" });
            });
          }
        })
        .catch((err) => {});
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .van-cell {
  background: rgba(255, 255, 255, 0.9);
}
</style>